package day14.BingFa;

import DiTie.Manager;

import java.util.concurrent.CountDownLatch;

public class CountDownLatchDome {
    public static void main(String[] args) {
        CountDownLatch countDownLatch = new CountDownLatch(3);
        Mother m=new Mother(countDownLatch);
        m.start();

        Chile1 c1=new Chile1(countDownLatch);
        c1.setName("大毛");
        c1.start();

        Chile1 c2=new Chile1(countDownLatch);
        c2.setName("大毛");
        c2.start();

        Chile1 c3=new Chile1(countDownLatch);
        c3.setName("大毛");
        c3.start();

    }
}

class Mother extends Thread {
    private  CountDownLatch countDownLatch;
    public Mother(CountDownLatch countDownLatch) {
        this.countDownLatch=countDownLatch;
    }
    @Override
    public void run() {
        try {
            countDownLatch.await();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("妈妈在收拾碗筷");
    }
}


class Chile1 extends Thread {
    private  CountDownLatch countDownLatch;
    public Chile1(CountDownLatch countDownLatch) {
        this.countDownLatch=countDownLatch;
    }
    @Override
    public void run() {
        for (int i = 1; i <= 10; i++) {
            System.out.println(Thread.currentThread().getName()+"在吃第"+i+"个饺子");
        }
        countDownLatch.countDown();
    }
}


class Chile2 extends Thread {
    private  CountDownLatch countDownLatch;
    public Chile2(CountDownLatch countDownLatch) {
        this.countDownLatch=countDownLatch;
    }
    @Override
    public void run() {
        for (int i = 1; i <= 15; i++) {
            System.out.println(Thread.currentThread().getName()+"在吃第"+i+"个饺子");
        }
        countDownLatch.countDown();
    }
}


class Chile3 extends Thread {
    private  CountDownLatch countDownLatch;
    public Chile3(CountDownLatch countDownLatch) {
        this.countDownLatch=countDownLatch;

    }
    @Override
    public void run() {
        for (int i = 1; i <= 20; i++) {
            System.out.println(Thread.currentThread().getName()
                    +"在吃第"+i+"个饺子");
        }
        countDownLatch.countDown();
    }
}
